package com.vishnu.main;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import com.vishnu.pojo.Employee;



public class LoadingDataIntoEmployee {

public static void main(String[] args) {
	Configuration configuration=new Configuration();
	configuration.configure("hib.cfg.xml");
	SessionFactory sf=configuration.buildSessionFactory();
	Session hsession=sf.openSession();
	Transaction transac=hsession.beginTransaction();
/*	Employee employee=new Employee();
	employee.setEmployeeId(2);
	hsession.delete(employee);*/
	System.out.println("------------------");
	
	Employee employee=new Employee();
	employee.setEmployeeId(24);
//	hsession.load(employee,15);
	employee.setEmployeeName("vishnuvardhan");
	employee.setEmployeeSalary(200.);
	hsession.save(employee);
	System.out.println("contains0="+hsession.contains(employee));
	hsession.flush();
//	hsession.merge(employee);
	System.out.println("contains1="+hsession.contains(employee));
//	Employee employee2=new Employee();
//	employee2.setEmployeeId(13);
//	hsession.saveOrUpdate(employee2);
	System.out.println("contains2="+hsession.contains(employee));
	hsession.evict(employee);
	System.out.println("contains3="+hsession.contains(employee));
//	hsession.load(employee, 1);
	
//	employee.setEmployeeName("raju");
//	employee.setEmployeeSalary(87565.);
//	hsession.update(employee);
//	employee=(Employee)hsession.get(employee.getClass(),4);
	if(employee!=null){
	System.out.println("EID="+employee.getEmployeeId());
	System.out.println("EName="+employee.getEmployeeName());
	System.out.println("ESalary="+employee.getEmployeeSalary());
	}else{
		System.out.println("No records are available..");
	}
	
	
	
	transac.commit();
	hsession.close();
	sf.close();
	
}
}
